// pages/report/report.js
const api=require('../../utils/request')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabNavActive:0,
    tableData:[],
    pageNum:1,
    pageSize:10,
    name:'',
    pages: 0,
    isLoading: false, // 是否正在加载更多
    isRefreshing: false, // 是否正在刷新
    noData: false, // 没有更多数据了
    gdLoading: true,
    dataType:["政策法规","柴油", "汽油"],
    jobTypeIndex:0,
    array: ['行业分类','柴油', '汽油' ],
    index: 0,
    isReport: false,
    typeTab:0,
    recentTagList:[],
    industryList:[],
    tagTypeIndex: 0,
    industryId:'',
    recentId:''
  },
  //类型切换状态
  typeIndex(e){
      if(e.currentTarget.dataset.index===0){
          this.setData({
            tagTypeIndex: 1
          })
      }
      if(e.currentTarget.dataset.index===1){
        this.setData({
            typeTab: 1
          })
      }
    
  },
    //政策法规
    bindPickerChange: function (e) {
        
      this.setData({
        jobTypeIndex: e.detail.value,
        tagTypeIndex: 1,
        recentId: this.data.recentTagList[e.detail.value].id
      });
       this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")

    },
      //行业分类
  bindPickerChange2: function (e) {
  
    this.setData({
      index: e.detail.value,
      typeTab: 1,
      industryId:this.data.industryList[e.detail.value].id
  });
  this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")

  },
  //类型切换
  jobTypeTab(e){
    console.log(e.currentTarget.dataset.index);
    this.setData({
      jobTypeIndex:e.currentTarget.dataset.index
    })
  },
  //预览图片
  showPic(e){
   // console.log(e);
    // 预览图片，放大预览
    wx.previewImage({
      urls: [e.currentTarget.dataset.img],
    })
  },
  kf(){
    //
   wx.openCustomerServiceChat({
       extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcdb659362f1afb3c0'},
       corpId: 'wwbb8c2c0fafdbf12b',
       success(res) {
           console.log('resss',res)
       }
     })
  },
  //回顶部
  toTop(){
		wx.pageScrollTo({
		    scrollTop: 0
		})
	},
   //下拉刷新
   handleRefresh(){
    if (this.data.isRefreshing) return;
    this.setData({
      isRefreshing: true,
      noData: false,
      gdLoading: true,
      pageNum:1
    },()=>{
      //请求数据
      this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")
    })
    setTimeout(()=>{
      this.setData({
        isRefreshing: false,
        noData: false
      });
  
    },2000)
  },
  clear(){
      this.setData({
        name:'',
        pageNum: 1
      })
      this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")
  },
  setInput(e){
    this.setData({
        name: e.detail.value
    })
},
  // 加载更多
  loadMore(){
     if(this.data.isLoading) return;
    this.loadData(this.data.pageNum++,this.data.pageSize++,this.data.name,"add")
    // this.setData({
    //   noData: true
    // }) 
  },
  tabNavClick(e){
    console.log(e.currentTarget.dataset.index);
    this.setData({
      tabNavActive : e.currentTarget.dataset.index
    })
  },

  loadRecent(){
      let that=this
      api.get('web/findTagLists/5').then(res=>{
    
        if(res.code===200){
            let array=[{name:'数据类型',id:''}]
            that.setData({
                recentTagList: array.concat(res.data==null?[]:res.data)
            })
        }
      })
  },
  loadIndustryList(){
    let that=this
      api.get('web/AllIndustryList').then(res=>{
        if(res.code===200){
            let array=[{name:'行业分类',id:''}]
            that.setData({
                industryList: array.concat(res.data)
            })
        }
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      this.loadRecent()
      this.loadIndustryList()
    this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")
  },
  changeData(){
     if(this.data.pages>this.data.pageNum){
        this.setData({
            pageNum: this.data.pageNum+1
        })
        this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,'add')
    }else{
       this.setData({
         gdLoading: false,
         noData: true
       })
    }
   },
   search(){
       this.setData({
           pageNum: 1
       })
       this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,"refresh")
    },
  loadData(pageNum,pageSize,name,type){
      let that=this
      wx.showLoading({
        title: '正在加载中…………',
      })
      const param={pageNum:pageNum,pageSize:pageSize,name:name,industryId:this.data.industryId,imageId:this.data.recentId}
      api.post('web/imageLists',param).then(response=>{
        console.log('数据图表-------',response)
        if(response.code===200){
            if( response.data.records.length===0){
                that.setData({
                 noData: true,
                 gdLoading: false
                })
            }else{
             that.setData({
                 noData: false,
                 gdLoading: true
                })
            }


          if(type=="refresh"){ //刷新
            that.setData({
                tableData:response.data.records,
                pages: response.data.pages
            });
          }else if(type=="add"){ //加载更多
            that.setData({
                tableData:this.data.tableData.concat(response.data.records),
                pages: response.data.pages
            });
          } 
           wx.hideLoading();
        }else{
          wx.hideLoading();
        }
      })
  },
  changePdf(e){
    let id=e.currentTarget.dataset.id
        wx.navigateTo({
            // 普通页面
            url:'../report/pdf/pdf?id='+id+'&backType=2'
          })
    
   
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  // onPullDownRefresh() {
  //   console.log('下拉')
    

  // },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.pages>this.data.pageNum){
        this.setData({
            pageNum: this.data.pageNum+1
        })
        this.loadData(this.data.pageNum,this.data.pageSize,this.data.name,'add')
    }else{
       this.setData({
         gdLoading: false,
         noData: true
       })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
        title: '新研报',
        path:'/pages/datas/datas',
        imageUrl: 'https://yw.xinyanbao.cn/2024-07-04/WechatIMG2171.jpg'                
      } 
  }
})